package com.study.samsung.Control;


import com.study.samsung.Entity.Commodity;
import com.study.samsung.Entity.Orders;
import com.study.samsung.Entity.Succession;
import com.study.samsung.Entity.User;
import com.study.samsung.Service.GoodsService;
import com.study.samsung.Service.IndexSearchService;
import com.study.samsung.Service.MyOrdersService;
import com.study.samsung.Service.OrderXqService;
import com.study.samsung.Utils.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/MyOrdershas")
public class MyOrdershas extends BaseServlet {
    MyOrdersService ms = new MyOrdersService();
    OrderXqService os = new OrderXqService();

    IndexSearchService iss = new IndexSearchService();
    GoodsService gds = new GoodsService();

    @Override
    public String excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        User users = (User) session.getAttribute("user");
        Integer uids = users.getUid();
        List<Orders> orders = ms.selectOrders(uids);
        List<Orders> ordersgoods = ms.selectAll(uids);
        System.out.println(orders);
        session.setAttribute("ordersgoods",ordersgoods);
        session.setAttribute("orders",orders);

        List<Commodity> newgoods = iss.selectnew();
        List<Succession> selectxl = iss.selectxl();

        request.setAttribute("newgoods",newgoods);
        request.setAttribute("selectxl",selectxl);

        Object user = session.getAttribute("user");
        if (user!=null){
            User nowuser = (User) user;
            Integer uid = nowuser.getUid();

            session.setAttribute("cartcount",gds.cartcount(uid));
        }
        return "f:MyOrdershasone";
    }

    public String two(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<Commodity> newgoods = iss.selectnew();
        List<Succession> selectxl = iss.selectxl();

        request.setAttribute("newgoods",newgoods);
        request.setAttribute("selectxl",selectxl);

        Object user = session.getAttribute("user");
        if (user!=null){
            User nowuser = (User) user;
            Integer uid = nowuser.getUid();

            session.setAttribute("cartcount",gds.cartcount(uid));
        }
        return "f:MyOrdershastwo";
    }

    public String three(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<Commodity> newgoods = iss.selectnew();
        List<Succession> selectxl = iss.selectxl();

        request.setAttribute("newgoods",newgoods);
        request.setAttribute("selectxl",selectxl);

        Object user = session.getAttribute("user");
        if (user!=null){
            User nowuser = (User) user;
            Integer uid = nowuser.getUid();

            session.setAttribute("cartcount",gds.cartcount(uid));
        }
        return "f:MyOrdershasthree";
    }

    public String four(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<Commodity> newgoods = iss.selectnew();
        List<Succession> selectxl = iss.selectxl();

        request.setAttribute("newgoods",newgoods);
        request.setAttribute("selectxl",selectxl);

        Object user = session.getAttribute("user");
        if (user!=null){
            User nowuser = (User) user;
            Integer uid = nowuser.getUid();

            session.setAttribute("cartcount",gds.cartcount(uid));
        }
        return "f:MyOrdershasfour";
    }

    public String five(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<Commodity> newgoods = iss.selectnew();
        List<Succession> selectxl = iss.selectxl();

        request.setAttribute("newgoods",newgoods);
        request.setAttribute("selectxl",selectxl);

        Object user = session.getAttribute("user");
        if (user!=null){
            User nowuser = (User) user;
            Integer uid = nowuser.getUid();

            session.setAttribute("cartcount",gds.cartcount(uid));
        }
        return "f:MyOrdershasFive";
    }

    public String orderdel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String orderdid = request.getParameter("orderdid");
        Integer did = Integer.parseInt(orderdid);
        Integer odxq = os.ordersxqdel(did);

        if (odxq>0){
            Integer od = ms.ordersdel(did);
            if (od>0){
                return "删除成功";
            }else {
                return "删除失败";
            }
        }else {
            return "删除失败";
        }

    }

    public String inquxiao(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        return "1111";
    }

    public Integer cancelorder(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String Did = request.getParameter("did");
        Integer did = Integer.parseInt(Did);
        Integer cancelorder = ms.cancelorder(did);
        return cancelorder;
    }

    public Integer paynow(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String Did = request.getParameter("did");
        Integer did = Integer.parseInt(Did);
        session.setAttribute("did",did);
        return 1;
    }
}
